package com.cqapp.widget.ui.search;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProviders;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.viewpager.widget.ViewPager;

import com.cqapp.entity.Fruit;
import com.cqapp.entity.FruitAdapter;
import com.cqapp.widget.R;
import com.cqapp.widget.ui.image.ImagePagerAdapter;

import java.util.ArrayList;
import java.util.List;


public class SearchFragmemt extends Fragment implements ViewPager.OnPageChangeListener{

    //几个代表页面的常量
    public static final int PAGE_ONE = 0;
    public static final int PAGE_TWO = 1;
    public static final int PAGE_THREE = 2;
    public static final int PAGE_FOUR = 3;

    private SearchViewModel searchViewModel;
    private ViewPager mPager;
    private ImagePagerAdapter mImagePagerAdapter;


    public View onCreateView(@NonNull LayoutInflater inflater,
                             ViewGroup container, Bundle savedInstanceState) {
        searchViewModel =
                ViewModelProviders.of(this).get(SearchViewModel.class);
        View root = inflater.inflate(R.layout.fragment_search, container, false);

        mPager = root.findViewById(R.id.mypager);

        //设置上部滑动的部分
        mImagePagerAdapter = new ImagePagerAdapter(this.getChildFragmentManager(),searchViewModel.getfragmentList());
        mPager.setAdapter(mImagePagerAdapter);
        mPager.setCurrentItem(0);
        mPager.addOnPageChangeListener(this);



        return root;
    }




    @Override
    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

    }

    @Override
    public void onPageSelected(int position) {

    }

    @Override
    public void onPageScrollStateChanged(int state) {

    }
}
